package com.bang.study.day01.test;

import java.util.Stack;

/**
 * @Auther: Bang
 * @Date: 2019/9/8 22:58
 * @Description:
 */
public class Solution {

    public static boolean isValid(String s){
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if ( c=='{'||c=='['||c=='(') {
                stack.push(c);
            }else{
                if (stack.empty()) {
                    return false;
                }else{
                    Character pop = stack.pop();
                    if (c==')'&&pop!='(') {
                        return false;
                    }
                    if (c==']'&&pop!='[') {
                        return false;
                    }
                    if (c=='}'&&pop!='{') {
                        return false;
                    }
                }
            }
        }
        return stack.empty();

    }

    public static void main(String[] args) {
        boolean valid = isValid("{((())}");
        System.out.println(valid);
    }
}
